<%@ page language="java" import="java.util.*,com.imaker.domain.*" pageEncoding="UTF-8"%>
<%
String path = request.getContextPath();
String basePath = request.getScheme()+"://"+request.getServerName()+":"+request.getServerPort()+path+"/";
List<Navigation> navList = (List<Navigation>)request.getAttribute("navList");
%>

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
  <head>
    <base href="<%=basePath%>">
	<meta http-equiv="pragma" content="no-cache">
	<meta http-equiv="cache-control" content="no-cache">
	<meta http-equiv="expires" content="0">    
	<meta http-equiv="keywords" content="keyword1,keyword2,keyword3">
	<meta http-equiv="description" content="This is my page">
	<link rel="stylesheet" href="<%=path%>/css/plugin/zTree/zTreeStyle.css" type="text/css">
	<link href="<%=path %>/css/system/core.css" rel="stylesheet" type="text/css">
	<script type="text/javascript" src="<%=path%>/js/jquery.js"></script>
	<script type="text/javascript" src="<%=path%>/js/plugin/zTree/ztree.js"></script>
	<script type="text/javascript" src="<%=path%>/js/zTreeSetting.js"></script>
	<script type="text/javascript">
	//创建节点
	zNodes =[
	{ id:1, pId:'0', name:"导航栏列表", "url":getUrl('00000000000000000000000000000000'), target:"listFrame"},
	<% if(navList!=null&&navList.size()>0){ 
		for(int i=0;i<navList.size();i++){
			Navigation nav = navList.get(i);
			if(i!=navList.size()-1){
	%>
		{ id:'<%=nav.getId() %>', pId:'<%=nav.getPid().equals("00000000000000000000000000000000")?'1':nav.getPid() %>', name:"<%=nav.getNavName() %>", "url":getUrl('<%=nav.getId() %>'), target:"listFrame"},
		<%}else {%>
		{ id:'<%=nav.getId() %>', pId:'<%=nav.getPid().equals("00000000000000000000000000000000")?'1':nav.getPid() %>', name:"<%=nav.getNavName() %>", "url":getUrl('<%=nav.getId() %>'), target:"listFrame"}
		<% }}} else {%>
		{ id:2, pId:'1', name:"暂无内容","url":getUrl('00000000000000000000000000000000'), target:"listFrame"}
		<% }%>
	];
	
	function getUrl(id){
	if(id==""){
	alert("节点无效");
	return;
	}
	return "<%=path %>/system/nav/listByPage.action?navigation.id="+id;
	}

	//创建子节点
	function add(){
	var pid = window.listFrame.form.pid.value;
	document.getElementById("listFrame").src = "<%=path %>/system/nav/toSave.action?navigation.id="+pid;
	}
	
	//更新
	function toupdate(){
	var array = $(window.frames["listFrame"].document).find("input[name='idList'][@checked]");
	var id;
	if(array!=null&&array.size()>0){
		id = array[0].value;
	  }else {
	  	alert("请选择一条数据");
	  	return;
	  }
	  document.getElementById("listFrame").src = "<%=path %>/system/nav/toUpdate.action?navigation.id="+id;
	}

	//删除
	function toDelete(){
		var array = $(window.frames["listFrame"].document).find("input[name='idList'][@checked]");
		if(array==null||array.size()==0){
			alert("请选择一条记录");
			return;
		}
		if(!confirm("确认删除？")){
			return;
		}
		window.listFrame.form.action = "<%=path %>/system/nav/delete.action";
		window.listFrame.form.submit();
	}
	</script>
  </head>
  <body>
  <div class="leftTree">
  <div class="treeMenu">导航栏列表</div>
  <ul id="tree" class="tree">
  		
  </ul>
  </div>
  <div class="rightTable">
  		<div class="title"></div>
  		<div class="line"></div>
  		<div class="menuBar">
  			<dl>
  					<dt class="new"></dt>
  					<dd><a href="javascript:void(0);" onclick="add()">新建</a></dd>
					<dt class="edit"></dd>
					<dd><a href="javascript:void(0);" onclick="toupdate()">修改</a></dd>
					<dt class="delete"></dd>
					<dd><a href="javascript:void(0);" onclick="toDelete()">删除</a></dd>
			</dl>
		</div>
		<div class="clearR"></div>
  		<div class="listFrame">
  			<iframe id="listFrame" name="listFrame" scrolling="no" frameborder="0"></iframe>
  		</div>
  </div>
  </body>
</html>
